﻿using BUS;
using DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EC21_EDiamond
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDanhMuc();
                LoadThuongHieu();
                LoadKhoanGia();
            }
            DataList1.DataSourceID = "ObjectDataSource1";
           // DataList2.Controls.Clear();
        }
        public void LoadDanhMuc()
        {
            DataTable dm = new DataTable();
            dm = DanhMucBUS.Ds_DanhMuc();
            DanhMucDTO tatca = new DanhMucDTO();
            tatca.MaDM = 0;
            tatca.TenDM = "Tất cả";
            dm.Rows.Add(0, tatca);
            ddlloaisp.DataSource = dm;
            ddlloaisp.DataTextField = "TenDM";
            ddlloaisp.DataValueField = "MaDM";
            ddlloaisp.DataBind();
        }
        public void LoadThuongHieu()
        {
            DataTable th = new DataTable();
            th = ThuongHieuBUS.DSTH();
            ThuongHieuDTO tatca = new ThuongHieuDTO();
            tatca.MaTH = 0;
            tatca.TenTH = "Tất cả";
            th.Rows.Add(0, tatca);
            ddlthuonghieu.DataSource = th;
            ddlthuonghieu.DataTextField = "TenTH";
            ddlthuonghieu.DataValueField = "MaTH";
            ddlthuonghieu.DataBind();
        }

        public void LoadKhoanGia()
        {
            List<Object> items = new List<object>();
            items.Add(new { value = 0, display = "Tất cả" });
            items.Add(new { value = 1, display = "Dưới 5.000.000" });
            items.Add(new { value = 2, display = "5.000.000 - 10.000.000" });
            items.Add(new { value = 3, display = "10.000.000 - 20.000.000" });
            items.Add(new { value = 4, display = "20.000.000 - 50.000.000" });
            items.Add(new { value = 5, display = "Trên 50.000.000" });

            ddlgia.DataSource = items;
            ddlgia.DataTextField = "display";
            ddlgia.DataValueField = "value";
            ddlgia.DataBind();
        }

        

        protected void btntim_Click(object sender, EventArgs e)
        {
            DataList1.DataSourceID="ObjectDataSource2";
            string url = "KetQuaTimKiem.aspx?tensp=" + txtim.Text + "&madm="+ddlloaisp.SelectedValue.ToString()+"&math="+ddlthuonghieu.SelectedValue.ToString()+"&gia="+ddlgia.SelectedValue.ToString() ;
            Response.Redirect(url);
        }
    }
}